<template>
  <div>
   <flexform ref="formRef" :formList="formList"></flexform>
    <n-button type="primary" block secondary strong @click="denglu">
      登录
    </n-button>
  </div>
</template>

<script setup name="denglu">
import {ref,onMounted,defineEmits,defineProps,nextTick,watch,computed} from "vue"
import {useRoute, useRouter} from "vue-router";
import {useLayout} from "../../store/moduls/layout";
import http from "@/request/request"
import {useUserInfo} from "../../store/moduls/userinfo";

const router = useRouter()
const route = useRoute()
const userInfo = useUserInfo()
const layoutaction = useLayout()
const formRef=ref(null)
const formList=ref([
  {label:"账号",type:"input",rules:[{required:true,message:"请输入账号",trigger:["input","change","blur"]},],placeholder:"请输入账号",key:"username"},
  {label:"密码",type:"input",rules:[{required:true,message:"请输入密码",trigger:["input","change","blur"]},],placeholder:"请输入密码",key:"password",password:"password",},
])
// 点击登录
const denglu=()=>{
  // formRef.value.jiaoyan(loginfunc)
  // console.log("点击登录")
  router.push({name:"Work"})
}
//
const loginfunc=(shuju)=>{
  console.log(shuju,"父组件收到")
  http.login(shuju).then(res=>{
    if(res.data.code===0){
      console.log("登录成功")
      userInfo.denglu(res.data.data)
      console.log("用户信息注册完毕")
      // 登录成功后，如果当前是锁定状态，解锁
      layoutaction.changelock(false)
      console.log("解除锁定")
      router.push({name:"Work"})
      console.log("跳转结束")
    }else{
      message.error(res.data.error.toString())
    }
  })
}
</script>


<style scoped>

</style>
